﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using CreditAgricole.Framework;
using CreditAgricole.Application;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;

namespace CreditAgricole.PageCodeBehind
{
    public class CommingSoonMep : WebControl
    {
        private List<VOBase> mepToDisplay;

        private Guid mepWebId;
        private Guid mepSiteId;

        public Guid MepWebId
        {
            get { return mepWebId; }
            set { mepWebId = value; }
        }

        public Guid MepSiteId
        {
            get { return mepSiteId; }
            set { mepSiteId = value; }
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            string startDate = SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.Today.AddDays(-7));
            string endDate = SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.Today.AddDays(7));
            mepToDisplay = DataMep.GetItemsByDate(MepSiteId, MepWebId, 
                                                  Constants.ChangingListTitle, 
                                                  SPContext.Current.Web.CurrentUser.ID, 
                                                  Constants.DueDateField, 
                                                  startDate, endDate);
            if (mepToDisplay.Count > 0)
            {
                Panel pnlTitleInfo = new Panel();
                Label lblTitleInfo = new Label();
                lblTitleInfo.Text = "Mise en production +/-7jours";
                pnlTitleInfo.Controls.Add(lblTitleInfo);
                Panel pnlDisplayInfo = new Panel();
                pnlDisplayInfo.CssClass = "display_mep_info";
                foreach (VOMep mep in mepToDisplay)
                {
                    Panel pnlMep = new Panel();
                    Label lblMepDate = new Label();
                    lblMepDate.Text = mep.DueDate.ToString();
                    Label lblMepTitle = new Label();
                    lblMepTitle.Text = mep.Title;
                    pnlMep.Controls.Add(lblMepDate);
                    pnlMep.Controls.Add(lblMepTitle);
                    pnlDisplayInfo.Controls.Add(pnlMep);
                }
                Controls.Add(pnlTitleInfo);
                Controls.Add(pnlDisplayInfo);
            }
        }
    }
}
